package com.cgbl.cg.view

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.cgbl.cg.R
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils

class CommonConfirmPop(context: Context) : CenterPopupView(context) {

    private lateinit var titleView: TextView

    private lateinit var leftView: TextView

    private lateinit var rightView: TextView

    private var titleText = ""

    private var leftText = ""

    private var rightText = ""

    private var leftTextColor = ColorUtils.getColor(R.color.app_color_7e)

    private var rightTextColor = ColorUtils.getColor(R.color.app_color_cc2d2d)

    private var titleTextColor = ColorUtils.getColor(R.color.app_color_42)

    private var leftClickListener: () -> Unit = {}

    private var rightClickListener: () -> Unit = {}


    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_common_confirm
    }

    override fun initPopupContent() {
        super.initPopupContent()
        titleView = findViewById(R.id.tv_title)
        leftView = findViewById(R.id.tv_left)
        rightView = findViewById(R.id.tv_right)
        titleView.apply {
            text = titleText
            setTextColor(titleTextColor)
        }

        leftView.apply {
            text = leftText
            setTextColor(leftTextColor)
            setOnClickListener {
                dismiss()
                leftClickListener.invoke()
            }
        }

        rightView.apply {
            text = rightText
            setTextColor(rightTextColor)
            setOnClickListener {
                dismiss()
                rightClickListener.invoke()
            }
        }
    }

    fun setTitle(title: String): CommonConfirmPop {
        titleText = title
        return this
    }

    fun setLeftText(left: String): CommonConfirmPop {
        leftText = left
        return this
    }

    fun setLeftTextColor(color: Int): CommonConfirmPop {
        leftTextColor = color
        return this
    }

    fun setRightTextColor(color: Int): CommonConfirmPop {
        rightTextColor = color
        return this
    }

    fun setRightText(right: String): CommonConfirmPop {
        rightText = right
        return this
    }

    fun setLeftClickListener(click: () -> Unit): CommonConfirmPop {
        leftClickListener = click
        return this
    }

    fun setRightClickListener(click: () -> Unit): CommonConfirmPop {
        rightClickListener = click
        return this
    }

    override fun getMaxWidth(): Int {
        return if (popupInfo.maxWidth == 0) XPopupUtils.getAppWidth(context) else popupInfo.maxWidth
    }

}